// Grayscale.cpp : implementation file
//

#include "stdafx.h"
#include "Grayscale.h"


// CGrayscale

CGrayscale::CGrayscale(float cr, float cg, float cb)
{
	this->m_cr = cr;
	this->m_cg = cg;
	this->m_cb = cb;
}

CGrayscale::~CGrayscale()
{
}

// CGrayscale member functions

BOOL CGrayscale::Apply(CxImage& srcImage, CxImage& destImage)
{
	if (srcImage.ResetIteration() && destImage.ResetIteration())
	{
		RGBQUAD value;
		while (srcImage.GetNextPixelColor(value))
		{
			value.rgbRed = value.rgbGreen = value.rgbBlue = 
				m_cr * value.rgbRed + m_cg * value.rgbGreen + m_cb * value.rgbBlue;
			destImage.SetNextPixelColor(value);
		}
		destImage.SetGrayScaled(TRUE);
		return TRUE;
	}
	return FALSE;
}

BOOL CGrayscale::Apply(CxImage& srcImage)
{
	if (srcImage.ResetIteration())
	{
		RGBQUAD value;
		while (srcImage.GetNextPixelColor(value))
		{
			value.rgbRed = value.rgbGreen = value.rgbBlue = 
				m_cr * value.rgbRed + m_cg * value.rgbGreen + m_cb * value.rgbBlue;
			srcImage.SetCurrentPixel(value);
		}
		srcImage.SetGrayScaled(TRUE);
		return TRUE;
	}
	return FALSE;
}